package Demo5;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int[] fenshu = new int[26];
        int[] geshu = new int[26];
        int sum = 0;
        for (int i = 0; i < fenshu.length; i++) {
            fenshu[i] = sc.nextInt();
        }
        for (int i = 0; i < s.length(); i++) {
            geshu[s.charAt(i)-'a']++;
        }
        for (int i = 0; i < geshu.length; i++) {
            System.out.print(geshu[i]);
            if (i != geshu.length-1){
                System.out.print(" ");
            }
            sum += (geshu[i] * fenshu[i]);
        }
        System.out.println();
        System.out.println(sum);
    }
}
